home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: cpp question
- Date: 22 Jan 1996 07:59:28 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4e0580$9v5@solutions.solon.com>
- References: <4drm99$j0m@peabody.colorado.edu> <4dtf1f$21r4@news.gate.net>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4dtf1f$21r4@news.gate.net>, William Hutto <bhutto@gate.net> wrote:
- >In article <4drm99$j0m@peabody.colorado.edu>,
- > woodjr@rintintin.Colorado.EDU (WOOD JAMEY RYAN) spake:
- >;I have something like this:
- >; #define USERLEN 8
- >; #define HOSTLEN 15
-
- >; char name[] = "woodjr";
- >; char host[] = "really.long.hostname.com";
- >; char s[100];
-
- >; sprintf(s, "%.USERLENs@%.HOSTLENs", name, host);
-
- >;And I want cpp to parse the sprintf line to:
-
- >; sprintf(s, "%.8s@%.15s", name, host);
-
- >;Which it (of course) isn't doing. Is there some syntax I
- >;can use to get it to do this?
-
- >There shur is:
-
- > sprintf(s, "%.*s@%.*s", USERLEN, name, HOSTLEN, host);
-
- >The asterisk in the width.precision fields in the formatting sequence allows
- >you to include the size as an integer value in your parameter list.
-
- Yes, but that doesn't do what he wants. How about
- #define STR(x) RSTR(x)
- #define RSTR(x) #x
-
- sprintf(s, "%." STR(USERLEN) "s@%." STR(HOSTLEN) "s", name , host);
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
- C/Unix proto-wizard -- C/Unix questions? Send mail for help. No, really!
- Using trn? Weird new newsgroup problem? I know the fix! Email me!
- The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
-